/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author David
 */
@Entity
@Table(name = "fitosanitari")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Fitosanitari.findAll", query = "SELECT f FROM Fitosanitari f"),
    @NamedQuery(name = "Fitosanitari.findById", query = "SELECT f FROM Fitosanitari f WHERE f.id = :id"),
    @NamedQuery(name = "Fitosanitari.findByNomComercial", query = "SELECT f FROM Fitosanitari f WHERE f.nomComercial = :nomComercial"),
    @NamedQuery(name = "Fitosanitari.findByMateriaActiva", query = "SELECT f FROM Fitosanitari f WHERE f.materiaActiva = :materiaActiva"),
    @NamedQuery(name = "Fitosanitari.findByComposicio", query = "SELECT f FROM Fitosanitari f WHERE f.composicio = :composicio"),
    @NamedQuery(name = "Fitosanitari.findByDosis", query = "SELECT f FROM Fitosanitari f WHERE f.dosis = :dosis"),
    @NamedQuery(name = "Fitosanitari.findByPlazSegurDies", query = "SELECT f FROM Fitosanitari f WHERE f.plazSegurDies = :plazSegurDies"),
    @NamedQuery(name = "Fitosanitari.findByProducAutortizats", query = "SELECT f FROM Fitosanitari f WHERE f.producAutortizats = :producAutortizats"),
    @NamedQuery(name = "Fitosanitari.findByDataFiAutoritzacio", query = "SELECT f FROM Fitosanitari f WHERE f.dataFiAutoritzacio = :dataFiAutoritzacio"),
    @NamedQuery(name = "Fitosanitari.findByNumRegistre", query = "SELECT f FROM Fitosanitari f WHERE f.numRegistre = :numRegistre")})
public class Fitosanitari implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "nom_comercial")
    private String nomComercial;
    @Basic(optional = false)
    @Column(name = "materia_activa")
    private String materiaActiva;
    @Column(name = "composicio")
    private String composicio;
    @Basic(optional = false)
    @Column(name = "dosis")
    private float dosis;
    @Basic(optional = false)
    @Column(name = "plaz_segur_dies")
    private int plazSegurDies;
    @Column(name = "produc_autortizats")
    private String producAutortizats;
    @Column(name = "data_fi_autoritzacio")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataFiAutoritzacio;
    @Column(name = "num_registre")
    private String numRegistre;
    @Lob
    @Column(name = "img")
    private byte[] img;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "fitosanitariId")
    private Collection<Tractament> tractamentCollection;
    @JoinColumn(name = "unitats_disolucio", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private UnitatsMesura unitatsDisolucio;
    @JoinColumn(name = "unitats_dosis", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private UnitatsMesura unitatsDosis;

    public Fitosanitari() {
    }

    public Fitosanitari(Integer id) {
        this.id = id;
    }

    public Fitosanitari(Integer id, String nomComercial, String materiaActiva, float dosis, int plazSegurDies) {
        this.id = id;
        this.nomComercial = nomComercial;
        this.materiaActiva = materiaActiva;
        this.dosis = dosis;
        this.plazSegurDies = plazSegurDies;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNomComercial() {
        return nomComercial;
    }

    public void setNomComercial(String nomComercial) {
        this.nomComercial = nomComercial;
    }

    public String getMateriaActiva() {
        return materiaActiva;
    }

    public void setMateriaActiva(String materiaActiva) {
        this.materiaActiva = materiaActiva;
    }

    public String getComposicio() {
        return composicio;
    }

    public void setComposicio(String composicio) {
        this.composicio = composicio;
    }

    public float getDosis() {
        return dosis;
    }

    public void setDosis(float dosis) {
        this.dosis = dosis;
    }

    public int getPlazSegurDies() {
        return plazSegurDies;
    }

    public void setPlazSegurDies(int plazSegurDies) {
        this.plazSegurDies = plazSegurDies;
    }

    public String getProducAutortizats() {
        return producAutortizats;
    }

    public void setProducAutortizats(String producAutortizats) {
        this.producAutortizats = producAutortizats;
    }

    public Date getDataFiAutoritzacio() {
        return dataFiAutoritzacio;
    }

    public void setDataFiAutoritzacio(Date dataFiAutoritzacio) {
        this.dataFiAutoritzacio = dataFiAutoritzacio;
    }

    public String getNumRegistre() {
        return numRegistre;
    }

    public void setNumRegistre(String numRegistre) {
        this.numRegistre = numRegistre;
    }

    public byte[] getImg() {
        return img;
    }

    public void setImg(byte[] img) {
        this.img = img;
    }

    @XmlTransient
    public Collection<Tractament> getTractamentCollection() {
        return tractamentCollection;
    }

    public void setTractamentCollection(Collection<Tractament> tractamentCollection) {
        this.tractamentCollection = tractamentCollection;
    }

    public UnitatsMesura getUnitatsDisolucio() {
        return unitatsDisolucio;
    }

    public void setUnitatsDisolucio(UnitatsMesura unitatsDisolucio) {
        this.unitatsDisolucio = unitatsDisolucio;
    }

    public UnitatsMesura getUnitatsDosis() {
        return unitatsDosis;
    }

    public void setUnitatsDosis(UnitatsMesura unitatsDosis) {
        this.unitatsDosis = unitatsDosis;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Fitosanitari)) {
            return false;
        }
        Fitosanitari other = (Fitosanitari) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Fitosanitari[ id=" + id + " ]";
    }
    
}
